package reading_text

import (
	"fmt"
	"log"
)

func AverageNum() {
	//从文本文件中获取数字，计算平均数
	numbers, err := GetFloats("./reading_text/data.txt")
	if err != nil {
		log.Fatal(err)
	}

	var sum float64 = 0

	for _, number := range numbers {
		sum += number
	}

	sampleCount := float64(len(numbers)) //获取类型为int的数组长度，并转化为float64
	fmt.Printf("Average: %0.2f\n", sum/sampleCount)
}
